import axios from 'axios'
import { MessageBox } from 'element-ui'

const instance = axios.create({
    baseURL: 'http://47.104.167.34:9110/api',
    timeout: 8000,
    // headers: { 'token': localStorage.getItem("token") }
})

instance.interceptors.request.use((config) => {
    config.headers.token = localStorage.getItem("token")
    return config
})

instance.interceptors.response.use((response) => {

    if (response.data.code == 401) {
        MessageBox.alert("登录已过期,请重新登录", "错误", {
            type: 'error',
            confirmButtonText: '去登陆'
        }).then(() => {
            localStorage.removeItem("token")
            window.location.reload();
        })
    }

    return response
})

export default instance